package com.example.service.Impl;

import com.example.service.BookService;
import com.example.dao.BookDao;
import com.example.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    private final BookDao bookDao;

    @Autowired
    public BookServiceImpl(BookDao bookDao) {
        this.bookDao = bookDao;
    }

    @Override
    @Transactional
    public void getAllBooks() {
        List<Book> books =bookDao.getAllBooks();
        System.out.println("全部的书籍详情:");
        for (Book book : books) {
            System.out.println(book); // 这里假设 Book 类已经重写了 toString 方法
        }
    }

    @Override
    @Transactional
    public void getBookById(int id) {
        System.out.println("您所查询的书籍详情");
        System.out.println(bookDao.getBookById(id));
    }

    @Override
    @Transactional
    public void addBook(Book book) {
        bookDao.addBook(book);
    }

    @Override
    @Transactional
    public void updateBook(Book book) {
        bookDao.updateBook(book);
    }

    @Override
    @Transactional
    public void deleteBook(int id) {
        bookDao.deleteBook(id);
    }
}
